package netty.http;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import netty.http.handler.TestHttpServerHandler;
import netty.simple.netty.ServerHandler;

/**
 * @ClassName TestServer
 * @Description TODO
 * @Author director吴
 * @Date 2022/2/16 13:01
 * @Version 1.0
 **/
public class TestServer {

    public static void main(String[] args) throws Exception {

        //两个线程组 group
        //两个线程组的线程个数  ==   默认 CPU 核心数 * 2
        EventLoopGroup bossGroup = new NioEventLoopGroup(1);
        EventLoopGroup workerGroup = new NioEventLoopGroup();

        try {
            //创建服务器端的启动对象
            ServerBootstrap serverBootstrapbootstrap = new ServerBootstrap();
            //链式设置
            serverBootstrapbootstrap.group(bossGroup, workerGroup)                             //设置   两个线程组
                    .channel(NioServerSocketChannel.class)                     //使用 NioServerSocketChannel .作为通道实现
                    .childHandler(new TestServerInitializer());  //给workGroup 对应的管道设置处理器


            ChannelFuture channelFuture = serverBootstrapbootstrap.bind(8082).sync();

            channelFuture.channel().closeFuture().sync();

        }finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
}
